package com.cargohu.aishouyu.member.controller;

import com.cargohu.aishouyu.common.CommonConstants;
import com.cargohu.aishouyu.framework.page.Paging;
import com.cargohu.aishouyu.framework.response.ApiResult;
import com.cargohu.aishouyu.member.dto.ChatHistoryAddDTO;
import com.cargohu.aishouyu.member.dto.ChatHistoryUpdateDTO;
import com.cargohu.aishouyu.member.req.ChatHistoryRequest;
import com.cargohu.aishouyu.member.resp.ChatHistoryDetailVo;
import com.cargohu.aishouyu.member.resp.ChatHistoryResponse;
import com.cargohu.aishouyu.member.service.ChatHistoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 聊天记录 控制器
 *
 * @author aaron.wang
 * @since 2023-11-27
 */
@Slf4j
@RestController
@RequestMapping(CommonConstants.API_ADMIN_PATH+"/chat-history")
@Tag(name = "聊天记录")
public class ChatHistoryController {

    @Autowired
    private ChatHistoryService chatHistoryService;

    /**
     * 添加聊天记录
     *
     * @param chatHistoryAddDTO
     * @return
     * @throws Exception
     */
    @PostMapping("/add")
    @Operation(summary = "添加聊天记录")
    public ApiResult addChatHistory(@Valid @RequestBody ChatHistoryAddDTO chatHistoryAddDTO) throws Exception {
        boolean flag = chatHistoryService.addChatHistory(chatHistoryAddDTO);
        return ApiResult.result(flag);
    }

    /**
     * 修改聊天记录
     *
     * @param chatHistoryUpdateDTO
     * @return
     * @throws Exception
     */
    @PostMapping("/update")
    @Operation(summary = "修改聊天记录")
    public ApiResult updateChatHistory(@Valid @RequestBody ChatHistoryUpdateDTO chatHistoryUpdateDTO) throws Exception {
        boolean flag = chatHistoryService.updateChatHistory(chatHistoryUpdateDTO);
        return ApiResult.result(flag);
    }

    /**
     * 删除聊天记录
     *
     * @param id
     * @return
     * @throws Exception
     */
    @PostMapping("/delete/{id}")
    @Operation(summary = "删除聊天记录")
    public ApiResult deleteChatHistory(@PathVariable Long id) throws Exception {
        boolean flag = chatHistoryService.deleteChatHistory(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取聊天记录详情
     *
     * @param id
     * @return
     * @throws Exception
     */
    @PostMapping("/get/{id}")
    @Operation(summary = "聊天记录详情")
    public ApiResult<ChatHistoryDetailVo> getChatHistory(@PathVariable Long id) throws Exception {
        ChatHistoryDetailVo chatHistoryDetailVo = chatHistoryService.getChatHistoryById(id);
        return ApiResult.success(chatHistoryDetailVo);
    }

    /**
     * 聊天记录分页列表
     *
     * @param chatHistoryRequest
     * @return
     * @throws Exception
     */
    @PostMapping("/page")
    @Operation(summary = "聊天记录分页列表")
    public ApiResult<ChatHistoryResponse> getChatHistoryList(@Valid @RequestBody ChatHistoryRequest chatHistoryRequest) throws Exception {
        Paging<ChatHistoryResponse> paging = chatHistoryService.getChatHistoryList(chatHistoryRequest);
        return ApiResult.success(paging);
    }

}
